import CryptoJS from 'crypto-js'

/**
 * AES 加密
 */
export const encryptData = (plaintext) => {
	const key = CryptoJS.enc.Utf8.parse('1234567890abcdef1234567890abcdef')
	const iv = CryptoJS.enc.Utf8.parse('abcdef1234567890')
	
	let encrypted = CryptoJS.AES.encrypt(plaintext, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7,
	})
	
	return encrypted.toString()
}

/**
 * AES 解密
 */
export const decryptedData = (encrypted) => {
	const key = CryptoJS.enc.Utf8.parse('1234567890abcdef1234567890abcdef')
	const iv = CryptoJS.enc.Utf8.parse('abcdef1234567890')
	
	let decrypted = CryptoJS.AES.decrypt(encrypted, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7,
	})
	
	return decrypted.toString(CryptoJS.enc.Utf8)
}
